package com.zyf.recallArithmetic;

import java.util.ArrayList;
import java.util.List;

public class Solution {

	public static void main(String[] args) {
		int n = 4;
		List<String> str = generateParenthesis(n);
		System.out.println("[");
		System.out.println("\"" + str + "\"");
		System.out.println("]");
	}

	static ArrayList<String> res = new ArrayList<>();

	public static List<String> generateParenthesis(int n) {
		dfs(n, n, "");
		return res;
	}

	public static void dfs(int left, int right, String curStr) {
		if (left == 0 && right == 0) {
			res.add(curStr);// 结果加入集合
			return;
		}
		if (left > 0)
			dfs(left - 1, right, curStr + "("); // 左大于0 拼接左括号
		if (right > left)
			dfs(left, right - 1, curStr + ")");// 右大于左，可以拼接右括号
	}
}
